package com.vegetable.modules.service.bank.convert;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import java.math.BigDecimal;
import java.util.Objects;

public class BankGenerator {

    public String getStringCell(Row currentR, int index){
        String result = "";
        Cell tCell = currentR.getCell(index);
        if(Objects.isNull(tCell)){
            return result;
        }
        switch (tCell.getCellType()){
            case NUMERIC:
                result = tCell.getNumericCellValue() + "";
                break;
            case STRING:
                result = tCell.getStringCellValue();
                break;
        }
        return result.trim();
    }

    public BigDecimal getBCCell(Row currentR, int index){
        BigDecimal result = BigDecimal.ZERO;
        Cell tCell = currentR.getCell(index);
        if(Objects.isNull(tCell)){
            return result;
        }
        switch (tCell.getCellType()){
            case NUMERIC:
                result = BigDecimal.valueOf(tCell.getNumericCellValue());
                break;
            case STRING:
                result = new BigDecimal(tCell.getStringCellValue().replace("\t", "").replace("-", "").replace("+", "").replace(",", ""));
                break;
        }
        return result;
    }

    public Double getDoubleCell(Row currentR, int index){
        double result = 0d;
        Cell tCell = currentR.getCell(index);
        if(Objects.isNull(tCell)){
            return result;
        }
        switch (tCell.getCellType()){
            case NUMERIC:
                result = tCell.getNumericCellValue();
                break;
            case STRING:
                result = Double.parseDouble(tCell.getStringCellValue());
                break;
        }
        return result;
    }

}
